#ifndef __FORWARD_SOCKET_H_INCLUDED__
#define __FORWARD_SOCKET_H_INCLUDED__

#include <sys/types.h>
#include <sys/socket.h>

#ifdef __cplusplus
extern "C" {
#endif

class forward_socket{

public:

	enum{
		INVALID = -1
	};

	enum TYPE{
		TCP,
		UDP
	};

	forward_socket();
	~forward_socket();

	bool is_valid();
	void auto_release(bool val);
	void attach(int s);
	int dettach();
	int fd();
	const char* to_string();

	int create(TYPE type);
	void close();
	int nonblocking(bool val);
	int reuseaddr(bool enable);
	int bind(uint16_t port);
	int listen(int backlog);
	int accept(sockaddr* addr, socklen_t* addrlen);
	int send(const void *buf, size_t len, int flags);
	int recv(void *buf, size_t len, int flags);
	int recvfrom(void *buf, size_t len, int flags, sockaddr* src_addr, socklen_t *addrlen);
	int sendto(const void *buf, size_t len, int flags, const sockaddr* dest_addr, socklen_t addrlen);
	int connect(const struct sockaddr *addr, socklen_t addrlen);

private:

	int s;
	bool ar;
};

#ifdef __cplusplus
}
#endif

#endif // __FORWARD_SOCKET_H_INCLUDED__
